<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>菜单列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/layui/css/layui.css" media="all">
    <script src="/static/admin/jquery/jquery-3.6.0.min.js"></script>
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    <legend>菜单列表节点操作</legend>
</fieldset>
<div class="layui-row">
    <div class="layui-col-md3">
        <button onclick="addMenu()" class="layui-btn layui-btn-normal">新增</button>
    </div>
</div>
<div id="test9" class="demo-tree demo-tree-box" style="width: 100%;  overflow: visible;"></div>

<script src="/static/admin/layui/layui.js" charset="utf-8"></script>
<script>
    layui.use(['tree', 'util'], function(){
        var tree = layui.tree
            ,layer = layui.layer
            ,util = layui.util


        var options;
        $(document).ready(function(){
            $.ajax({
                type : "POST",  //提交方式
                url : "{:url('/admin/auth/menu')}",//路径
                data : {},
                success: function(data){
                    console.log(data)
                    if(data.code === 0){
                        options = data.data;
                        layui.use('tree', function(){
                            var tree = layui.tree;
                            //渲染
                            var inst1 = tree.render({
                                elem: '#test9'  //绑定元素
                                ,data: options
                                // ,edit: ['add', 'update', 'del'] //操作节点的图标
                                ,click: function(obj){
                                    data = obj.data
                                    addMenu(data.id);
                                    // layer.msg(JSON.stringify(obj.data));
                                }
                            });
                        });
                    }else{
                        layer.msg('获取失败！')
                    }
                }
            })
        })
    });
    function addMenu(id=0){
        var url,title
        if(id == 0){
            url = "{:url('auth/menu_add')}";
            title = '新增菜单';
        }else{
            url = "{:url('auth/menu_edit')}?id=" + id;
            title = '修改菜单';
        }
        layer.open({
            type: 2
            , title: title
            , area: ['800px', '400px']
            , skin: 'layui-layer-rim'
            , shade: 0.8
            , content: url
        });
    }
</script>

</body>
</html>